import sys
import unittest
sys.path.append("D:\wordSpace\langchainQA")


import asyncio
from typing import List
from BCEmbedding import RerankerModel
from app.config.model_config import  RERANKER_MODEL,EMBEDDING_DEVICE_MAP
from app.utils.singleton import SignletonFunc,Singleton
class BaseReRank(RerankerModel,metaclass=Singleton):
    def __init__(self, model_name_or_path: str = RERANKER_MODEL, use_fp16: bool = True, device: str = EMBEDDING_DEVICE_MAP['ranker_model'], **kwargs):
        super().__init__(model_name_or_path, use_fp16, device, **kwargs)
    def  arerank(self,query:str,passages:List[str]):
        return asyncio.get_event_loop().run_in_executor(None, self.rerank,query,passages)
baseReRank=BaseReRank()

# class TestBaseDocumentCompressor(unittest.TestCase):
#     def test_init(self):
#         # Test with default parameters
#         compressor = BaseReRank()
#         self.assertIsNotNone(compressor)
        
#         # Test with custom parameters
#         custom_model_name = "custom_model"
#         custom_use_fp16 = False
#         custom_device = "cpu"
#         compressor = BaseReRank(model_name_or_path=custom_model_name, use_fp16=custom_use_fp16, device=custom_device)
#         self.assertIsNotNone(compressor)
#         self.assertEqual(compressor.model_name_or_path, custom_model_name)
#         self.assertEqual(compressor.use_fp16, custom_use_fp16)
#         self.assertEqual(compressor.device, custom_device)


if __name__ == '__main__':
    BaseReRank()